package com.baidu.process.chat.core.web.bean.eval;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import lombok.Data;

/**
 * @Author:fangyuchao
 * @Description:
 * @Date: Create in 9:50 2022/11/7
 */
@Data
public class EvalResult {

    /**
     * 返回编码 0为成功，其余皆是失败
     */
    private int returnCode;

    /**
     * 对应提示信息
     */
    private String returnMessage;

    /**
     * 返回实体的json字符串
     */
    private String jsonString;

    /**
     * 成功
     * @return
     */
    public static EvalResult ok () {
        EvalResult result = new EvalResult();
        result.setReturnCode(0);
        result.setReturnMessage("success");
        return result;
    }

    /**
     * 成功(带实体)
     * @param data
     * @return
     */
    public static EvalResult ok (Object data) {
        EvalResult result = new EvalResult();
        result.setReturnCode(0);
        result.setReturnMessage("success");
        result.setJsonString(JSONObject.toJSONString(data, SerializerFeature.WriteNullListAsEmpty));
        return result;
    }

    /**
     * 失败
     * @param errMsg
     * @return
     */
    public static EvalResult fail (String errMsg) {
        EvalResult result = new EvalResult();
        result.setReturnCode(1);
        result.setReturnMessage(errMsg);
        return result;
    }
}
